package ligne2vie.topos.client.maps.listeners;

import ligne2vie.topos.client.maps.MyMapWidget;
import ligne2vie.topos.shared.bo.TMapPoint;

import com.google.gwt.maps.client.base.InfoWindow;
import com.google.gwt.maps.client.event.EventCallback;

/**
 * The class {@link OpenInfoWindowOnClick} allows displaying an information window about the map point which has just
 * been clicked on the point.
 * 
 * @author thuguerre
 * @since 1.0.0
 */
public class OpenInfoWindowOnClick extends EventCallback {

	private TMapPoint mapPoint;

	/**
	 * Default constructor.
	 * 
	 * @param mapElement
	 *            The element which will be clicked.
	 * @param mapPoint
	 *            Corresponding map point.
	 */
	public OpenInfoWindowOnClick(TMapPoint mapPoint) {
		this.mapPoint = mapPoint;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void callback() {

		// --- creating info window object

		InfoWindow iw = new InfoWindow();
		iw.setContent(mapPoint.getInfoWindowContent());

		// --- opening info window on the map

		MyMapWidget.getInstance().openInfoWindow(mapPoint.getMarker(), iw);
	}
}
